package com.zrrd.blog.article.api;

import com.zrrd.blog.article.service.IArticleService;
import com.zrrd.blog.article.req.ArticleListREQ;
import com.zrrd.blog.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "文章访问接口(不需要登录)",description = "不需要登录就能访问的文章接口，不做身份验证")
@RestController
@RequestMapping("/api/article")
public class ApiArticleController {
    @Autowired
    private IArticleService articleService;

    @ApiOperation("根据id查询文章详情")
    @ApiImplicitParam(name="id",value = "文章id",required = true)
    @GetMapping("/{id}")
    public Result view(@PathVariable String id){
        return articleService.findArticleAndLabelById(id);
    }

    @ApiOperation("更新浏览次数")
    @PutMapping("/viewCount/{id}")
    public Result updateViewCount(@PathVariable("id") String id){
        return articleService.updateViewCount(id);
    }

    @ApiOperation("查询某个分类下的公开且公共的文章列表")
    @PostMapping("/list")
    public Result list(@RequestBody ArticleListREQ req){
        return articleService.findListByLabelIdOrCategoryId(req);
    }
}
